<!--
  * 地址对照
-->
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="证载地址" class="smart-query-form-itme" name="certAddress">
        <a-input style="width: 300px" v-model:value="queryForm.certAddress" placeholder="请输入证载地址" />
      </a-form-item>

      <a-form-item label="楼盘" class="smart-query-form-itme" name="communityName">
        <a-input style="width: 200px" v-model:value="queryForm.communityName" placeholder="请输入楼盘名称" />
      </a-form-item>

      <a-form-item label="楼栋全称" class="smart-query-form-itme" name="buildingName">
        <a-input style="width: 200px" v-model:value="queryForm.buildingName" placeholder="请输入楼栋全称" />
      </a-form-item>

      <a-form-item label="楼栋地址" class="smart-query-form-itme" name="buildingAddr">
        <a-input style="width: 200px" v-model:value="queryForm.buildingAddr" placeholder="请输入楼栋地址" />
      </a-form-item>

      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button type="primary" @click="ajaxQuery">
          <template #icon>
            <SearchOutlined />
          </template>
          查询
        </a-button>
        <a-button @click="resetQuery">
          <template #icon>
            <ReloadOutlined />
          </template>
          重置
        </a-button>
      </a-form-item>
    </a-row>
  </a-form>

  <a-card size="small" :bordered="false" :hoverable="true">
    <a-row class="smart-table-btn-block">
      <div class="smart-table-operate-block">
        <a-button @click="doInit('lookup')" v-privilege="'as:lookup:initdata'" type="primary" size="small">
          <template #icon>
            <CaretRightOutlined />
          </template>
          对照表初始化
        </a-button>
        <a-button @click="doInit('seg')" v-privilege="'as:lookup:initWords'" type="primary" size="small">
          <template #icon>
            <CloudSyncOutlined />
          </template>
          初始化分词库
        </a-button>
        <a-button @click="doInit('es')" v-privilege="'as:lookup:initEs'" type="primary" size="small">
          <template #icon>
            <CloudUploadOutlined />
          </template>
          初始化es
        </a-button>
      </div>
    </a-row>
    <a-table
      :scroll="{ x: 1300 }"
      size="small"
      :dataSource="tableData"
      :columns="columns"
      rowKey="house_code"
      :pagination="false"
      :loading="tableLoading"
      bordered
    >
      <!-- <template #bodyCell="{ column, record, text }">
        <template v-if="column.dataIndex === 'taskName'">
          <a @click="detail(record.id,record.taskName)">{{ text }}</a>
        </template>
        <template v-if="column.dataIndex === 'action'">
          <div class="smart-table-operate">
            <a-button v-if=" record.state==='2' " @click="doSeg(record.id)" v-privilege="'as:task:seg'" type="link">分词</a-button>
            <a-button v-if=" record.state==='3' " @click="doFix(record.id)" v-privilege="'as:task:fix'" type="link">修复</a-button>
            <a-button v-if=" record.state==='4' " @click="doMatch(record.id)" v-privilege="'as:task:match'" type="link">匹配</a-button>
            <a-button v-if=" record.state==='0' " @click="update(record)" v-privilege="'as:task:edit'" type="link">编辑</a-button>
            <a-button v-if=" record.state==='0' " @click="confirmDelete(record.enterpriseId)" danger v-privilege="'as:task:delete'" type="link">删除</a-button>
          </div>
        </template>
      </template> -->
    </a-table>

    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        showQuickJumper
        show-less-items
        :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize"
        v-model:current="queryForm.pageIndex"
        v-model:pageSize="queryForm.pageSize"
        :total="total"
        @change="ajaxQuery"
        @showSizeChange="ajaxQuery"
        :show-total="(total) => `共${total}条`"
      />
    </div>
  </a-card>
  <CheckCity ref="checkCityRef" />
</template>

<script setup lang="ts">
  import { reactive, ref, onMounted,computed } from 'vue';
  import { asApi } from '/@/api/addrstandard/as-api'
  import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '/@/constants/common-const';
  import { smartSentry } from '/@/lib/smart-sentry';
  import CheckCity from './check-city-modal.vue'

  // --------------------------- 企业表格 列 ---------------------------

  const columns = ref([
    {
      title: '证载地址',
      dataIndex: 'certAddress',
      minWidth: 180,
      // ellipsis: true,
    },
    {
      title: '楼盘名称',
      dataIndex: 'communityName',
      width: 180,
      ellipsis: true,
    },
    {
      title: '楼栋地址',
      dataIndex: 'buildingAddr',
      width: 180,
      ellipsis: true,
    },
    {
      title: '楼栋全称',
      dataIndex: 'buildingName',
      width: 180,
    },
    {
      title: '幢/栋',
      dataIndex: 'buildingNum',
      width: 80,
    },
    {
      title: '单元/梯/座',
      dataIndex: 'unitNum',
      width: 100,
    },
    {
      title: '房号',
      width: 80,
      dataIndex: 'houseNumber',
      ellipsis: true,
    },
    {
      title: '省',
      width: 80,
      dataIndex: 'proviceName',
      ellipsis: true,
    },
    {
      title: '市',
      width: 80,
      dataIndex: 'cityName',
      ellipsis: true,
    },
    {
      title: '区',
      dataIndex: 'districtName',
      fixed: 'right',
      width: 80,
    },
  ]);

  // --------------------------- 查询 ---------------------------

  const queryFormState = {
    certAddress: undefined,
    communityName: undefined,
    buildingName: undefined,
    buildingAddr: undefined,
    pageIndex: 1,
    pageSize: PAGE_SIZE,
  };
  const queryForm = reactive({ ...queryFormState });
  const tableLoading = ref(false);
  const tableData = ref([]);
  const total = ref(0);
  const checkCityRef =ref();

  function resetQuery() {
    Object.assign(queryForm, queryFormState);
    ajaxQuery();
  }

  async function ajaxQuery() {
    try {
      tableLoading.value = true;
      let responseModel = await asApi.lookUpPageQuery(queryForm);
      const list = responseModel.data.data;
      total.value = responseModel.data.total;
      tableData.value = list;
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      tableLoading.value = false;
    }
  }

  function doInit(type:string){
    checkCityRef.value.showModal(type);
   }
  onMounted(ajaxQuery);
</script>
